﻿/*
 * Copyright © 2020, Wuxi Safover Intelligent Technology Co., Ltd. All rights reserved.
 * 
 * 无锡安永智能科技有限公司版权所有，未经许可，不得用于商业用途
 * 
 * Visit: https://www.safover.com/ 
 */

using log4net;
using System;
using System.Reflection;
using Safover.LidarCollector.Models;
using Safover.LidarCollector.Config;
using Safover.Lidar.DataContract;

namespace Safover.LidarCollector.Managers
{
    public class LidarPacketSaver
    {
        protected static readonly ILog Log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);

        private static bool SaveToDB => RuntimeConfigManager.Instance.OthersConfig.SaveToDB;
        private static bool SaveToFile => RuntimeConfigManager.Instance.OthersConfig.SaveToFile;

        public static void Save(LidarRawFrame frame)
        {
            if (SaveToFile)
            {
                GetLidarPacketFileSaver().Save(frame);
            }

            if (SaveToDB)
            {
                // TODO:
            }
        }

        public static void SaveAsync(LidarRawFrame frame)
        {
            throw new NotImplementedException();
        }

        private static LidarPacketFileSaver GetLidarPacketFileSaver()
        {
            switch (AppConfig.FileSaverVersion)
            {
                case FileSaverVersion.V1:
                    return new V1LidarPacketFileSaver();
                case FileSaverVersion.V2:
                    return new V2LidarPacketFileSaver();
                default:
                    throw new NotImplementedException($"No available file saver for {AppConfig.FileSaverVersion}");
            }
        }
    }
}
